#include "MenuScene.h"
#include "HelloWorldScene.h"

cocos2d::Scene* MenuScene::createScene()
{
	return MenuScene::create();
}

bool MenuScene::init()
{
	if (!Scene::init())
	{
		return false;
	}

	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("touming-hd.plist");

	auto lable = Label::create("lableItem", "fonts/arial.ttf",25);
	auto _sprNormal = Sprite::create("btn-play-normal.png");
	auto _sprPress = Sprite::create("btn-play-selected.png");
	auto _normal = Sprite::createWithSpriteFrameName("speed12.png");
	auto _press = Sprite::createWithSpriteFrameName("speed21.png");
	MenuItem* normal = MenuItemSprite::create(_normal, _normal);
	MenuItem* press = MenuItemSprite::create(_press, _press);
	/*MenuItemFont* item1 = MenuItemFont::create("changeScene", CC_CALLBACK_1(MenuScene::menuClickHandler, this));
	MenuItemFont* item2 = MenuItemFont::create("item2", CC_CALLBACK_1(MenuScene::menuClickHandler, this));
	MenuItemFont* item3 = MenuItemFont::create("item3", CC_CALLBACK_1(MenuScene::menuClickHandler, this));*/
	MenuItemLabel* item1 = MenuItemLabel::create(lable, CC_CALLBACK_1(MenuScene::menuClickHandler, this));
	MenuItemFont* item2 = MenuItemFont::create("changeScene", CC_CALLBACK_1(MenuScene::menuClickHandler, this));
	MenuItemSprite* item3 = MenuItemSprite::create(_sprNormal,_sprPress,CC_CALLBACK_1(MenuScene::menuClickHandler, this));
	MenuItemImage* item4 = MenuItemImage::create("f1.png", "f2.png", CC_CALLBACK_1(MenuScene::menuClickHandler, this));
	MenuItemToggle* item5 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuScene::menuClickHandler, this), normal, press, nullptr);

	item1->setTag(1);
	item2->setTag(2);
	item3->setTag(3);
	item4->setTag(4);
	//item5->setTag(5);

	item3->setScale(0.5);
	item4->setScale(0.5);

	Menu* menu = Menu::create(item1, item2, item3, item4, item5, nullptr);
	menu->alignItemsVerticallyWithPadding(20);
	this->addChild(menu);
	//menu->setPosition(100, 200);
	return true;
}

void MenuScene::menuClickHandler(Ref *ref)
{
	MenuItem* item = (MenuItem*)ref;
	CCLOG("MenuItem was clicked!Its tag is %d",item->getTag());
	if (item->getTag() == 2) {
		auto scene = HelloWorld::createScene();
		Director::getInstance()->replaceScene(scene);
	}
}